1. Field of the Invention
The present invention relates to a microcomputer in which a programmable nonvolatile memory such as a flash memory is built, and more specifically, to a function of rewriting the nonvolatile memory.
2. Description of the Prior Art
Up to this time, a microcomputer characterized by the following was conventionally known: having dedicated hardware (H/W), that is to say, an automatic sequence circuit, which controls rewriting of content of a flash memory that is built in the microcomputer; and a CPU (central processing unit) of the microcomputer writes or sets a control command to the hardware, and thereby starts up hardware operation for rewriting. In this case, it was necessary for a user to transfer a rewriting control program having a function of issuing a command, and the like, to a built-in RAM under the control of the user. In addition, it was also necessary to inhibit interrupt on the user side (Example: M37902FGCHP produced by Mitsubishi Electric Corporation).
Because this rewriting processing was automatically performed by the hardware, the rewriting control program, which should be prepared on the user side, could be simplified to some degree. However, on the other hand, a layout area of an automatic sequence circuit was large, which resulted in high cost. Moreover, repair of the hardware was required to perform bug fixing of a rewriting sequence and to adapt the rewriting sequence to wafer process most suitably. The repair, however, could not be carried out easily.
On the other hand, there is also a case in which only a required minimum of automatic sequence circuits for rewriting control is provided. In this case, even time management, and comparison/judgment of a result, which are required for rewriting processing, are performed by software (S/W) on the user side (Examples: M37754FFCHP produced by Mitsubishi Electric Corporation, H8/3062F-ZTAT produced by Hitachi, Ltd.).
Because the quantity of the hardware is small, low-cost chips can be produced. On the other hand, the following problem arises: a load of the rewriting control software, which should be made on the user side, is heavy resulting in a long software development period.
In addition, a programmable-nonvolatile-memory device and a microcomputer using the same, are described in international application WO99/01824. The microcomputer comprises a control register for outputting a signal, which controls circuits (a sense amplifier, and a step-up circuit) relating to rewriting of an EEPROM (a nonvolatile memory) in the microcomputer. A means for rewriting the EEPROM by writing data directly from outside of the microcomputer to this control register successively is disclosed in the international application. Its object is to reduce cost by removing a rewriting control circuit.
This reference describes a control technology for writing required data from a writer, which is outside the microcomputer, to this control register. However, rewriting of the nonvolatile memory while user software is being operated is not described in this reference.
Moreover, although the reference states that a CPU of the microcomputer is capable of writing data to this control register in a xe2x80x9cSerial I/O modexe2x80x9d in which a serial writer is used, there is no description other than that. There is no description of where the control software is specifically placed at the time of writing, and of how it operates.
In the EEPROM, reading is limited to a memory bit as an object to be rewritten. As a result, it is comparatively easy to manage the control software. However, practically, in the case of the microcomputer with built-in flash memory, reading cannot be performed when rewriting the flash memory that stores the control program. Therefore, the following limitations become indispensable conditions: executing by the control program on the built-in RAM; inhibiting interrupt; and the like. Management of this control software is very important for the microcomputer with built-in flash memory. In other words, in this rewriting technology of the microcomputer with built-in EEPROM, which uses the writer, rewriting of the flash memory during user software operation cannot possibly be realized.
The conventional microcomputers with built-in programmable nonvolatile memory are configured as described above. As a result, concerning the microcomputer with an automatic sequence circuit, there are problems in that a layout area is large, resulting in high cost; and a change in sequence is not easy. On the other hand, concerning the microcomputer that does not has the automatic sequence circuit, there are problems in that a load of rewriting control software on the user side is heavy, resulting in a long software development period.
The present invention has been made to solve the problems described above. An object of the present invention is to obtain a microcomputer with built-in programmable nonvolatile memory that is capable of the followings: decreasing a layout area by removing an automatic sequence circuit, and thereby aiming at low cost; facilitating a change in a rewriting sequence for bug fixing and for adapting the rewriting sequence to a wafer process most suitably; and reducing a load of user side software, and also shortening a software development period, by loading rewriting control firmware (F/W).
According to an aspect of the present invention, there is provided a microcomputer with built-in programmable nonvolatile memory, the microcomputer comprising: a nonvolatile memory for storing rewriting control firmware and user software in separate unit blocks respectively; at least four registers, which can be written or read by a CPU of the microcomputer: a command register for specifying content of rewriting control; an address register for specifying an address to be subjected to rewriting control; a data register for specifying data to be written; and a control signal register for specifying a control signal for a power-supply pump circuit in a nonvolatile memory and a memory decoder; wherein: the power-supply pump circuit and the memory decoder are controlled by associating given bits of the control signal register with control signals connected to the power-supply pump circuit and the memory decoder; and the rewriting control firmware reads a value that is set in the command register, the address register, or the data register, and rewrites a set value in the control signal register according to a sequence specified for each command corresponding to the read value, which is set in the command register, the address register, or the data register, to operate the power-supply pump circuit and the memory decoder, thereby executing rewriting processing including xe2x80x9cerasexe2x80x9d and xe2x80x9cprogramxe2x80x9d of the nonvolatile memory.
In this case, a unit block for storing the rewriting control firmware and a unit block for storing the user software may be configured so that addresses of both blocks are not consecutive.
In addition, the microcomputer with built-in programmable nonvolatile memory may comprise a status register that can be written or read by a CPU, wherein after completion of rewriting processing that includes xe2x80x9cerasexe2x80x9d and xe2x80x9cprogramxe2x80x9d, the rewriting control firmware writes a result of the execution into the status register.
Moreover, the rewriting control firmware comprises a user interface control unit for decoding at least a command that is set in the command register, and a command-execution control unit for controlling the power-supply pump circuit and the memory decoder for each specified command; and firmware of this command-execution control unit is transferred to a built-in RAM, and is executed on this RAM.
The rewriting control firmware is configured to start up as a result of a jump from the user software to a top address of the rewriting control firmware, and to return to a next instruction of the jump instruction in the user software after command execution is completed.
In the case of an xe2x80x9cerasexe2x80x9d command, the rewriting control firmware executes the xe2x80x9cerasexe2x80x9d and verification after the xe2x80x9cerasexe2x80x9d consecutively; in the case of a xe2x80x9cprogramxe2x80x9d command, the rewriting control firmware executes the xe2x80x9cprogramxe2x80x9d and verification after the xe2x80x9cprogramxe2x80x9d consecutively; and if a result of the verification is abnormal, it is judged to be an erase error or a program error respectively.
The rewriting control firmware sets a result of command execution including xe2x80x9cerasexe2x80x9d and xe2x80x9cprogramxe2x80x9d in the status register; and if a command, which is not a legal command code, or an address, which is not allowed to be specified, is specified in the command register or in the address register, an error code indicating an illegal command is set in the status register, and in this case, processing may not be performed hereafter.
The rewriting control firmware does not clear the status register, and reads the status register before executing a command that is set in the command register; and if a result of the status reading is an error code other than normal termination, the rewriting control firmware may not perform processing hereafter.
In addition, a number of bits of a command code, which should be written to the command register, ranges from 12 to 16. Moreover, the rewriting control firmware may decode all of the bits of this command code.
A number of bits of an address, which should be written to the address register, may be taken more than a number of bits of an address that can specify a nonvolatile memory space. Moreover, the rewriting control firmware may decode all of the bits of this address.
Furthermore, the microcomputer with built-in programmable nonvolatile memory may comprise a nonvolatile memory rewriting-mode selection bit that can be set by the CPU, wherein the control signal register can be rewritten when a specific value is written to this firmware rewriting-mode selection bit.
The control signal register may be a register that can be set by the CPU; and a control signal, which is output from the control signal register, may reset the power-supply pump circuit and the memory decoder by a reset signal, to a state in which rewriting is prohibited.
The control signal register may be a register that can be set by the CPU; and a control signal, which is output from the control signal register, may reset the power-supply pump circuit and the memory decoder by a watchdog-timer interrupt signal, to a state in which rewriting is prohibited.
The firmware-rewriting-mode selection bit may be configured to be reset to a state, in which a non-rewriting mode is specified, not only by a reset signal of the microcomputer but also by the watchdog-timer interrupt signal.
An accumulator in the CPU may be allocated as a command register.
Both or either of the command register and the status register may be allocated not to registers but to specific addresses in the built-in RAM.
The microcomputer with built-in programmable nonvolatile memory may comprise a dedicated timer circuit used when the nonvolatile memory is rewritten.
The microcomputer with built-in programmable nonvolatile memory may comprise a clock switching circuit for switching an operation clock source for the CPU and the peripheral device to a clock inputted from a clock terminal or to a clock generated by a built-in self-excited oscillator, wherein: these clocks are switched according to a state of the clock-source selection bit that can be set by the CPU; and at the time of rewriting of the nonvolatile memory, a clock on the self-excited oscillator side is selected.
The microcomputer with built-in programmable nonvolatile memory may comprise a clock switching circuit for switching an operation clock source for the CPU to a clock inputted from a clock terminal or to a clock generated by a built-in self-excited oscillator, wherein: these clocks are switched according to a state of the clock-source selection bit that can be set by the CPU; and at the time of rewriting of the nonvolatile memory, a clock on the self-excited oscillator side is selected as an operation clock source for the CPU, while a clock source for peripheral devices such as a timer and a serial I/O is not switched from the clock inputted from the clock terminal.
The microcomputer with built-in programmable nonvolatile memory may comprise a clock switching circuit for switching an operation clock source for the CPU and a watchdog timer to a clock inputted from a clock terminal or to a clock generated by a built-in self-excited oscillator, wherein: these clocks are switched according to a state of the clock-source selection bit that can be set by the CPU; and at the time of rewriting of the nonvolatile memory, a clock on the self-excited oscillator side is selected as an operation clock source for the CPU and the watchdog timer, while a clock source for peripheral devices such as a timer and a serial I/O is not switched from the clock inputted from the clock terminal.
The self-excited oscillator for the voltage charge pump in the nonvolatile memory may also be used for the built-in self-excited oscillator.
The self-excited oscillator for the voltage charge pump in the nonvolatile memory may also be used for a clock source of a timer circuit.
The self-excited oscillator may not operated continuously; a oscillation permission bit, which can be set by the CPU, is provided; and if this bit is in a specific state, the self-excited oscillator is operated.
For the switching of an operation clock source, the operation clock source may be allowed to be switched to a clock generated by the self-excited oscillator if a clock generated by the self-excited oscillator is selected by the clock-source selection bit, and if operation permission of the self-excited oscillator is selected by the oscillation permission bit.
The microcomputer with built-in programmable nonvolatile memory may include a plurality of operation modes, which are determined by a voltage level applied to an operation-mode-selection input terminal, wherein at least one operation mode is configured to prohibit rewriting of a rewriting-control-firmware storing area of the nonvolatile memory.
The microcomputer with built-in programmable nonvolatile memory may include a plurality of operation modes that are determined by a voltage level applied to an operation-mode-selection input terminal, wherein: a second operation mode is configured as a mode in which a reset vector address that is accessed after reset is cleared is in an external area; and in this second operation mode, at least an area for storing user software in the nonvolatile memory cannot be read from the CPU, while rewriting of the area for storing user software in the nonvolatile memory and an area for storing rewriting control firmware is permitted.
In the second operation mode, the area for storing rewriting control firmware in the nonvolatile memory may be read by the CPU.
The microcomputer with built-in programmable nonvolatile memory may include a plurality of operation modes that are determined by a voltage level applied to an operation-mode-selection input terminal, wherein: a third operation mode is configured as a mode in which a reset vector address that is accessed after reset is cleared is in an external area; and in this third operation mode, the nonvolatile memory area can be read from the CPU, while rewriting of the area for storing user software in the nonvolatile memory and the area for storing rewriting control firmware is permitted.
The microcomputer with built-in programmable nonvolatile memory may include a plurality of operation modes that are determined by a voltage level applied to an operation-mode-selection input terminal, wherein: a fourth operation mode is configured as a mode in which direct writing to a built-in RAM from outside during resetting is permitted, and in which a reset vector address after clearing the reset is set in the RAM; and in this fourth operation mode, the nonvolatile memory area can be read from the CPU, while rewriting of the area for storing user software in the nonvolatile memory and the area for storing rewriting control firmware is permitted.
A state of the operation-mode-selection input terminal may be read by the CPU.
The rewriting control firmware may read a state of the operation-mode-selection input terminal; and in the operation mode in which rewriting of the firmware area of the nonvolatile memory is prohibited, the rewriting-control-firmware storing area of the nonvolatile memory may not be rewritten, and it may be judged to be an illegal command.
The microcomputer with built-in programmable nonvolatile memory may include a rewriting command for firmware storing area which is enabled in an operation mode in which rewriting of the rewriting-control-firmware storing area of the nonvolatile memory is permitted.